home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Commodore Free 27
/
Commodore_Free_Issue_27_2009_Commodore_Computer_Club.d64
/
beginning 12-1
< prev
next >
Wrap
Text File
|
2023-02-26
|
11KB
|
415 lines
..
In the Beginning Part 12
Lord Ronin from Q-Link
Sound was a bit short for my
rambling prattle, the problem was I
ran out of lines as well as workable
examples for the different C=
machines. I mentioned that there are
programmes to make sounds and music
for you, there are also many books to
teach you more on the subject of
music. What I didn't mention is that
in the users manual has data for the
notes all 124, along with other
information for their use.
We are now at page 91, moving into
Advanced Data Handling. Time has past
since that last sentence and now; my
directory said that at that time
there were just three blocks written
in this section. While there are
around 13 pages in the Commodore
Users Guide left to handle before the
appendices. Going over the
information in that last section,
before writing my editorial comments
to the material. Man they jumped
through the stuff faster than I did
with the sound section. This might
scare you, and so might the titles of
the topics covered. Read and Data,
Averages, Subscripted Variables, One
dimension arrays, Averages revisited,
Dimension, Simulated dice roll with
arrays and Two dimensional arrays.
Alien and scary terms, when I went
through it the first time I was
scared myself. Scares some of the
locals as well when they see the
information, and not just for the
first time. Yet the authors crammed
that information into about 13 pages.
What we are going to do now is cover
that information, along with my
comments on my experiences in the use
of these sections. Including things
that we have done, tried to do and
want to do in programming.
READ DATA is the first thing
presented on page 92. Doing that
sprite program we had the start of
with Read Data. Type in the following
little program, It will give an error
msg. But that is a part of the
lesson.
10 readx
20 ?"x is now : ";x
30 goto10
40 data 1,34,10.5,16,234,56
You can see that it is going to read
the x variable. Then print it in that
X IS NOW : print statement. Got that
loop in 30. On screen you see that it
prints the value of X as each one of
the data entries on line 40. Then
gives "? OUT OF DATA ERROR IN 10".
Each time it loops through the X
part of the read. A pointer is given
by the computer to keep track of the
value to be used next. In this
program the loop keeps going till
there is not a single part in the
data statement to use. So it is OUT
OF DATA. That error is in line 10,
this is Because there isn't anything
more for it for it to read, as
ordered in line 10. Well that is
nice, but a bit useless, and I have
seen many programmes give me that
same error. A handful I have been
able to fix. No not ones that I typed
in, ones that came on disks to me
written in Basic.
Parts of the DATA statement to
understand. You have Got to start the
line off with the word DATA. OK you
can write it as dA for the shorthand.
Each part of the line of information
must be separated by a comma. This
thinggy here , and nothing else. The
Program will crash with different
error message to you. If you use any
other symbols, Or it may give you a
wrong data read out.
Now then what can go into a DATA
statement line? Most of what we have
dealt with already. Integer numbers,
real numbers, you remember the ones
with the numbers to the right of the
decimal point. Number in scientific
notation. You can even put in words
as well. But you CAN'T put in other
variables or math functions. DATA
Z$,12+5,6/3,5*5 is RIGHT OUT!! Not
going to happen as you would like.
Next type in is a little different
because it uses afor next loop to
keep that out of data error off the
screen.
new
10 forx=1to3
15 reada$
20 ?"a$ is now : ";a$
30 next
40 data i, did, this
Yeah it will print out each line,
going down the screen saying what a$
is each time. What happens if you add
50 goto10
Right the return to 10 starts the
program back but you are going to get
the out of data error message, not a
good thing; So in order to reuse the
data just add this line.
45 restore
You don't get the out of data, and
the program keeps going on forever.
What happens is that the data pointer
is restored each time through. Not a
big thing at this time for you to
follow.
Next is a more practical programme
for read/data.
new
10 t=0:ct=0
20 ifx=-1then50
25 ct=ct+1
30 t=t+x
40 goto10
50 ?"there were ";ct;"values read"
60 ?"total = ";t
70 ?"average =";t/ct
80 data 75,80,62,91,87,93,78,-1
You can probably guess what is going
to happen in some degree. Programme
is going to read all the data and
then print out the number of values
read. In this case it is 7 then by
the math in line 70 the program
prints the average after printing the
total. Here the total is 566 and the
average is 80.8571429.
The print statements are easy to
see. Setting the T and CT variables
to 0 at the start is simple. In fact
just about all of what we see in that
program is stuff we have done
already, everything except; there is
this strange thing in line 20 about a
-1. Also in line 80 is that -1 at the
end of the data statement line what
does that one mean? They call it a
flag, it is the indicator that the
read/data part is over. The Program
sees that -1 and then goes to line
50. Where it does the print and math
work. Line 20 is the check for that
flag of -1. No it doesn't have to be
a -1 in your programme. Can be
anything that isn't a part of what
you are placing in the data
statement, I have seen words and
strange numbers used in some type in
programmes. Anything that is out of
sorts with the theme of your
programme can be used for a flag. You
can make a large collection of data
statements, several lines worth, and
not worry about the count thing. When
using this flag concept.
Now here is the last part they give
on the read/data part, showing how to
assign data to a variable.
new
10 read n$,a,b,c
20 ?n$;"'s scores were: ";a;" ";b"
";c
30 ?"and the average is: ";(a+b+c)/3
40 ?:goto10
50 data
mike,190,185,165,dick,225,245,190
60 data
john,155,185,205,paul,160,179,187
Running this and you will get
something like...
mike's scores were: 190 185 165
and the average is : 180
Then the other three follow below
that one. Difference in this one is
that the order to be read is set in
line 10. Starting with n$ <name
string> and following with three sets
of variables for the integers. This
data is written in the data statement
lines in the same manner a text and
then the numbers.
Small little program that is to give
a basic understanding of how this
works. Obviously it can be bigger and
things like entering the data from a
programme can be done as well. I have
seen read/data statements in many a
Basic programs that I saved from
Q-Link. The first one that I tried to
work upon was an Inn Menu for Fantasy
Role Playing games. Altering the text
to fit different games I messed it up
royally. You see I didn't understand
the concepts of the flag and the read
a certain amount of data Or the point
about correctly placing in text in
the text area and numbers in the
number area. Now that I have learned
more I really should try that project
again.
Subscripted Variable, is the next
part; ends right after that above
program. Don't let the words freak
you out. May not have been the best
choice of terms to use for this type
of variable. What this leads into is
one of the mega important parts of
Basic programming, at least from the
part that my group is trying to do at
this time. I'll talk a bit on that
later.
Variables we have seen are like F$,
F%, F. Covering the text integer and
real numbers with the floating
decimal. We also learned that you can
have two characters for a variable.
Like F1$, F1%, F1. Or FA$, FA%, and
FA. That can give us a mess of
variables. Little slots of memory
that we can fill in with things. Now
we are going to expand upon that
idea.
Z(1) is a new thing. Got that the Z
is the variable. What then is the (1)
part? That is the subscripted
section. Even tells us how to say it
as "Z sub 1". Really this is
different than Z1 or even Z. Z(1) is
subscripted. Yeah I know first time
through this is confusing. They give
a chart thing to try to show you what
they mean. Looks something like this,
Z(0)
Z(1)
Z(2)
Z(3)
Z(4)
As an attempt to show you the memory
aspects of a subscripted variable.
The way that I see it is that there
is in the above 5 <0-4> slots in the
variable Z. Slots that something can
be put into.
10 Z(0)=25:Z(3)=55:Z(4)=-45.5
A modified form of what they present
next, as a way to see the thing about
putting stuff into those slots.
Modifying the boxes again, it would
look sort of like this in the memory
for Z.
Z(0) 25
Z(1)
Z(2)
Z(3) 55
Z(4) -45.3
Personally I like the effect of the
expanding box to illustrate the fact
that the size isn't set to just one
or two characters.
New word now, ARRAY. A group of
subscripted variables is called an
array. This one is a one dimensional
one. You can make multidimensional
arrays as well. Mind boggling isn't
it? Gets even more so, as you can be
more complex by adding other
variables or "computations". These
are CORRECT subscripted variables.
Z(X) Z(X+1) Z(2+1) Z(1*3)
Got that? Well it is still weak for
me. Point is that here we have a lot
more power than expected for our PC.
Even if you don't programme, you can
see now that we have more than people
think we have, these days. Now add to
this what we have seen already.
Couple this sort of subscripted
variable with things like Input and
Read statements. Right it is past us
at this time. They don't even try to
explain the how it is done part, only
mention it on page 97. New type in
program for you.
new
5 ?"<shift clear home>"
10 input"how many numbers :";x
20 fora=1tox
30 ?"enter value # ";a;:inputb(a)
40 next
50 su=0
60 fora=1tox
70 su=su+b(a)
80 next
90 ?:?"average = ";su/x
Right it wants to know how many
numbers you are going to insert. Then
it will have you enter each one.
Printing it to the screen. Finally it
will give you the average of all the
numbers.
When you run this I want you to say
that you want 5 numbers and the
numbers that you type in will be 125
167 189 167 158. The reason for this
will be shown a few paragraphs below.
These are the numbers that are
presented in the Commodore users
guide.
We have x as the counter for the
loop. The values are entered and go
into the subscripted variable of b.
Every time it loops through the
variable of A is increased. That is
pretty straight forward. Ah but what
is happening is not that straight
forward with what we understand at
this point. Certainly a is changing.
But not the way we have learned
before. First time through the loop.
We have a=1. OK got that part, the
difference is that it is entered into
the subscripted variable of b. So it
would be written, in the manner of
the boxes above asB(1). Next loop
through thevalue of A=2. This is
entered in the b subscripted variable
looking sort of like B(2) from the
above chart theme thing. this goes on
till the number of entries is
completed.
CONTINUED IN 12-2